<?php require_once('Connections/RecursosHumanos.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE objetivos SET ID_OBJETIVO=%s, NUM_EMPLEDO=%s, ID_EVALUACION=%s, DESCRIPCIONOBJETIVO=%s, FECHAINICO=%s, FECHAFIN=%s, `_CUMPLIMIENTO`=%s, `_PODERADO`=%s WHERE ANO=%s",
                       GetSQLValueString($_POST['ID_OBJETIVO'], "text"),
                       GetSQLValueString($_POST['NUM_EMPLEDO'], "text"),
                       GetSQLValueString($_POST['ID_EVALUACION'], "text"),
                       GetSQLValueString($_POST['DESCRIPCIONOBJETIVO'], "text"),
                       GetSQLValueString($_POST['FECHAINICO'], "date"),
                       GetSQLValueString($_POST['FECHAFIN'], "date"),
                       GetSQLValueString($_POST['_CUMPLIMIENTO'], "double"),
                       GetSQLValueString($_POST['_PODERADO'], "double"),
                       GetSQLValueString($_POST['ANO'], "int"));

  mysql_select_db($database_RecursosHumanos, $RecursosHumanos);
  $Result1 = mysql_query($updateSQL, $RecursosHumanos) or die(mysql_error());

  $updateGoTo = "CrearObjetivos.php?AnoEnv=" . $row_actu['ANO'] . "&EmpleadoEnv=" . $row_actu['NUM_EMPLEDO'] . "&EvaluacionEnv=" . $row_actu['ID_EVALUACION'] . "";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

mysql_select_db($database_RecursosHumanos, $RecursosHumanos);
$query_actu = "SELECT objetivos.ANO, objetivos.NUM_EMPLEDO, objetivos.ID_EVALUACION FROM objetivos";
$actu = mysql_query($query_actu, $RecursosHumanos) or die(mysql_error());
$row_actu = mysql_fetch_assoc($actu);
$totalRows_actu = mysql_num_rows($actu);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
</head>

<body>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
  <table align="center">
    <tr valign="baseline">
      <td nowrap align="right">ID_OBJETIVO:</td>
      <td><input type="text" name="ID_OBJETIVO" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">ANO:</td>
      <td><?php echo $row_actu['ANO']; ?></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">NUM_EMPLEDO:</td>
      <td><input type="text" name="NUM_EMPLEDO" value="<?php echo $row_actu['NUM_EMPLEDO']; ?>" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">ID_EVALUACION:</td>
      <td><input type="text" name="ID_EVALUACION" value="<?php echo $row_actu['ID_EVALUACION']; ?>" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">DESCRIPCIONOBJETIVO:</td>
      <td><input type="text" name="DESCRIPCIONOBJETIVO" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">FECHAINICO:</td>
      <td><input type="text" name="FECHAINICO" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">FECHAFIN:</td>
      <td><input type="text" name="FECHAFIN" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">_CUMPLIMIENTO:</td>
      <td><input type="text" name="_CUMPLIMIENTO" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">_PODERADO:</td>
      <td><input type="text" name="_PODERADO" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">&nbsp;</td>
      <td><input type="submit" value="Actualizar registro"></td>
    </tr>
  </table>
  <input type="hidden" name="MM_update" value="form1">
  <input type="hidden" name="ANO" value="<?php echo $row_actu['ANO']; ?>">
</form>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($actu);
?>
